import React, { Component,Suspense } from 'react'
import {Switch,Route,Redirect} from "react-router-dom"
import {RouterPROPS} from "../types/router.d"

export class RouterView extends Component<RouterPROPS> {
  render() {
      const {routerConfig} =this.props
    return (
      <Suspense fallback="路由加载中">
          <Switch>
              {routerConfig&&routerConfig.map((item,index)=>{
                  return item.redirect ? <Redirect key={index} to={item.redirect}></Redirect> :
                  <Route key={index} path={item.path} render={(props)=>{
                      return <item.component {...props} routerConfig={item.children}></item.component>
                  }}></Route>
              })}
          </Switch>
      </Suspense>
    )
  }
}

export default RouterView